package com.demo.designmode.visitor;

import com.demo.designmode.reponseibility.Handler;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: jxm
 * @Description: 对象结构类
 * @Date: 2023-12-12 15:34
 * @Version: 1.0
 */
public class Home {

    //声明集合对象用来存储元素对象
    private List<Animal> nodeList;

    public Home(){
        nodeList = new ArrayList<>();
    }

    //添加元素功能
    public void add(Animal animal){
        nodeList.add(animal);
    }

    //接收访问者访问
    public void action(Person person){
        //遍历集合,让访问者访问每一个元素
        for (Animal animal : nodeList) {
            animal.accept(person);
        }
    }
}
